package bdd;

import java.sql.*;

/**
 * Class de connexion à la base de données NE PAS COMMITTER VOS CHANGEMENTS DE
 * PARAMETRE DE CONNEXION !
 *
 * @author Loïc Jacolin-Lescot
 */
public class ConnectBDD {

    private static Connection nvConnexion = null;

    public static synchronized Connection getSingleton() throws ClassNotFoundException, SQLException {
        if (nvConnexion == null) {
            ConnectBDD tmp = new ConnectBDD();
        }
        return nvConnexion;

    }

    private ConnectBDD() throws ClassNotFoundException, SQLException {
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

        String url = "jdbc:sqlserver://localhost;database=shop_v3";
        String user = "sa";
        String pwd = "sa";
        //String url="jdbc:sqlserver://localhost:1433;databaseName=shop_v3;integratedSecurity=true;";

        //System.out.println("Connexion en cours...");
        nvConnexion = DriverManager.getConnection(url, user, pwd);
        //System.out.println("Connecté !");
    }

    public static void fermer() throws SQLException {
        nvConnexion.close();
        if (nvConnexion.isClosed()) {
            System.out.println("Déconnecté !");
        }
        nvConnexion = null;
    }
}
